package io.xccit.race.controller;

import io.xccit.common.annotation.Log;
import io.xccit.common.core.controller.BaseController;
import io.xccit.common.core.domain.AjaxResult;
import io.xccit.common.core.page.TableDataInfo;
import io.xccit.common.enums.BusinessType;
import io.xccit.common.utils.poi.ExcelUtil;
import io.xccit.race.domain.RaceCompetitionTeamMember;
import io.xccit.race.service.IRaceCompetitionTeamMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 团队报名成员Controller
 * 
 * @author ywx
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/race/teamMember")
public class RaceCompetitionTeamMemberController extends BaseController
{
    @Autowired
    private IRaceCompetitionTeamMemberService raceCompetitionTeamMemberService;

    /**
     * 查询团队报名成员列表
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:list')")
    @GetMapping("/list")
    public TableDataInfo list(RaceCompetitionTeamMember raceCompetitionTeamMember)
    {
        startPage();
        List<RaceCompetitionTeamMember> list = raceCompetitionTeamMemberService.selectRaceCompetitionTeamMemberList(raceCompetitionTeamMember);
        return getDataTable(list);
    }

    /**
     * 根据报名ID查询团队成员列表
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:list')")
    @GetMapping("/listBySignupId/{signupId}")
    public AjaxResult listBySignupId(@PathVariable("signupId") Long signupId)
    {
        List<RaceCompetitionTeamMember> list = raceCompetitionTeamMemberService.selectTeamMembersBySignupId(signupId);
        return success(list);
    }

    /**
     * 导出团队报名成员列表
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:export')")
    @Log(title = "团队报名成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RaceCompetitionTeamMember raceCompetitionTeamMember)
    {
        List<RaceCompetitionTeamMember> list = raceCompetitionTeamMemberService.selectRaceCompetitionTeamMemberList(raceCompetitionTeamMember);
        ExcelUtil<RaceCompetitionTeamMember> util = new ExcelUtil<RaceCompetitionTeamMember>(RaceCompetitionTeamMember.class);
        util.exportExcel(response, list, "团队报名成员数据");
    }

    /**
     * 获取团队报名成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(raceCompetitionTeamMemberService.selectRaceCompetitionTeamMemberById(id));
    }

    /**
     * 新增团队报名成员
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:add')")
    @Log(title = "团队报名成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RaceCompetitionTeamMember raceCompetitionTeamMember)
    {
        return toAjax(raceCompetitionTeamMemberService.insertRaceCompetitionTeamMember(raceCompetitionTeamMember));
    }

    /**
     * 修改团队报名成员
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:edit')")
    @Log(title = "团队报名成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RaceCompetitionTeamMember raceCompetitionTeamMember)
    {
        return toAjax(raceCompetitionTeamMemberService.updateRaceCompetitionTeamMember(raceCompetitionTeamMember));
    }

    /**
     * 删除团队报名成员
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:remove')")
    @Log(title = "团队报名成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(raceCompetitionTeamMemberService.deleteRaceCompetitionTeamMemberByIds(ids));
    }

    /**
     * 根据报名ID删除所有团队成员
     */
    @PreAuthorize("@ss.hasPermi('race:teamMember:remove')")
    @Log(title = "团队报名成员", businessType = BusinessType.DELETE)
    @DeleteMapping("/bySignupId/{signupId}")
    public AjaxResult removeBySignupId(@PathVariable("signupId") Long signupId)
    {
        return toAjax(raceCompetitionTeamMemberService.deleteTeamMembersBySignupId(signupId));
    }
}
